﻿Imports Publics

Public Class FrmChonNhanVienPhucVu

    Private _objNhanVien As DM_NhanVien
    Public Property objNhanVien() As DM_NhanVien
        Get
            Return _objNhanVien
        End Get
        Set(ByVal value As DM_NhanVien)
            _objNhanVien = value
        End Set
    End Property

    Private Sub FrmChonNhanVienPhucVu_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Windows.Forms.Keys.Enter Then
            btnChon_ItemClick(Nothing, Nothing)
        End If
        If e.KeyCode = Windows.Forms.Keys.Escape Then
            btnThoat_ItemClick(Nothing, Nothing)
        End If
    End Sub

    Private Sub FrmChonNhanVienPhucVu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillDataToGrid()
    End Sub
    Private Sub FillDataToGrid()
        grdNhanVien.DataSource = (From ds In dbTV.DM_NhanViens Where ds.InUsed Select New With { _
                                   .ID = ds.ID, .MaNhanVien = ds.MaSo, .TenNhanVien = ds.HoTen}).ToList
        grdNhanVien.RefreshDataSource()
    End Sub

    Private Sub btnChon_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnChon.ItemClick
        If grvNhanVien.FocusedRowHandle < 0 Then
            Return
        End If
        Dim strID = grvNhanVien.GetRowCellValue(grvNhanVien.FocusedRowHandle, grdColIDNhanVien).ToString
        Dim obj = (From ds In dbTV.DM_NhanViens Where ds.InUsed AndAlso ds.ID = strID Select ds).FirstOrDefault
        If obj IsNot Nothing Then
            objNhanVien = obj
            Me.Close()
        End If

    End Sub

    Private Sub btnThoat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnThoat.ItemClick
        objNhanVien = Nothing
        Me.Close()
    End Sub
End Class